const UserDao = require('../dao/users')
const {Err} = require("../factories/errors");
const JWT = require("../services/jwt.service");
const {createErrorResponse} = require("../factories/responses/api");

module.exports = async (req, res, next) => {
    try{
        const vip = await UserDao.isVip1(1)
        if (vip) {
            return next();
        } else {
            const err = new Err(`Format for : Bearer [token]`);
            err.status = 405;
            throw err;
        }
    }catch (error) {
        console.error(error)
        // If error is not our custom error, log it.
        if (error.name !== Err.name)
            console.error("refreshToken.policy error:", error);
        else
            error.name = '只有 VIP 用户才有权限访问此内容';

        return createErrorResponse({
            res,
            error,
            status: error?.statusCode ?? 401
        });
    }
}
